package com.example.gmranqi.common.conver;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * @des: 自定义转换器
 * @Author: 高总辉
 * @Date 2019/9/9 7:55
 */
public interface Covert<S,D> {

    D covertTD(S s);

    S covertTS(D d);

    default List<D> covertTDList(List<S> list) {
        if (list == null || list.isEmpty()) {
            return new ArrayList<>();
        }
        return list.stream().filter(Objects::nonNull).map(this::covertTD).filter(Objects::nonNull).collect(Collectors.toList());
    }

    default List<S> covertTSList(List<D> list) {
        if (list == null || list.isEmpty()) {
            return new ArrayList<>();
        }
        return list.stream().filter(Objects::nonNull).map(this::covertTS).filter(Objects::nonNull).collect(Collectors.toList());
    }
}
